<?php
namespace Home\Controller;
use Think\Controller;
class StoreController extends Controller {
    public function login(){
    	if(IS_POST){
    		$user = M('User');
    		$password = I('password');
    		$where['account'] = I('account');
    		$store = $user->where($where)->find();
    		if($store){
    			if($store['password']==md5($password)){
    				$where2['uid'] = $store['id'];
    				$store['ordernum'] = M("Order")->where($where2)->count();
    				//     	//将时间点转换为时间戳
    				$dates = array();
    				$date = time();
    				$dates[] = date('Y-m-d',$date);
    				$dates[] = date('Y-m-d',$date - 1*24*60*60);
    				$dates[] = date('Y-m-d',$date - 2*24*60*60);
    				$where2['cdate'] = array('in',$dates);
    				//输出一天前的日期，在时间戳上减去一天的秒数
    				$store['cartnum'] = M("Cart")->where($where2)->count();
    				$token = md5($store['id'].time());
    				$data['token'] = $token;
    				$store['token'] = $token;
    				$user->where(array('id'=>$store['id']))->save($data);
    				session('store',$store);
    				$this->success("登录成功",__APP__."/Home/Food/index");
    			}else{
    				$this->error("账号或者密码错误");
    			}
    		}else{
    			$this->error("账号不存在");
    		}
    	}else{
    		$this->display();
    	}
    }
    public function logout(){
    	session_unset();
    	session_destroy();
    	$this->redirect('Home/Index/login');
    }
}